﻿; (function (window, undefined, $) {
    $(document).ready(function () {
        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'Id', width: "5%", sortable: true, hide: true, align: 'left', iskey: true },
                
                    { display: '项目', name: 'ProjectName', width: "10%", sortable: false, hide: false, align: 'left' },
                    { display: '金额（元）', name: 'Amount', width: "7%", sortable: false, align: 'left' },
                    { display: '回报内容', name: 'MRedoundContent', width: "15%", sortable: false, align: 'left' },
                    { display: '回报类别', name: 'RedoundType', width: "7%", sortable: false, align: 'left', process: RedoundType },
                    { display: '回报简介', name: 'RedoundContent', width: "5%", sortable: false, align: 'left' },
                    { display: '说明图片', name: 'RedoundImage', width: "7%", sortable: false, align: 'left', process: RedoundImage },
                    { display: '限定名额', name: 'Limits', width: "7%", sortable: false, align: 'left', process: LimitsPeople },
                    { display: '运费(元)', name: 'Freight', width: "7%", sortable: false, align: 'left' },
                    { display: '回报时间(项目结束后（天）)', name: 'DedoundDays', width: "7%", sortable: false, align: 'left' },
                  /*  { display: '创建时间', name: 'Createtime', width: "7%", sortable: false, hide: true, align: 'left' },*/
                    { display: '操作', name: 'Id', width: "15%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "Id",
            sortorder: "ASC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            /*  ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>编辑</a>");*/
            ops.push("&nbsp;<a title='投资情况' href='javascript:;'  onclick=\"util.InvestmentInformation('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>投资情况</a>");
            //ops.push("&nbsp;<a title='删除' href='javascript:;'  onclick=\"util.Delete('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>删除</a>");
            return ops.join("");
        }

        function LimitsPeople(value,cell) {
            if (value==0) {
                return '不限人数';
            } else {
                return value;
            }
        }
        function RedoundType(value, cell) {
            if (value == 0) {
                return '实物';
            } else {
                return '虚拟物品回报(电子码等)';
            }
        }

        function RedoundImage(value, cell) {
            return '<img id="imgShow" style="width: 100px; height: 50px" src="' + value + '" />';
        }


        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });

        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });

        $("#btnAdd").click(function () {
            var url = options.editUrl + "/?projectId=" + $("#projectId").val();
            location.href = url;
        });

        /*util.Edit = function (id) {
            var url = options.editUrl + "/?id=" + id;
            location.href = url;
        };*/

        util.InvestmentInformation = function (id) {
            var url = options.investmentInformationUrl + "/?id=" + id;
            location.href = url;
        };

        util.Delete = function (id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + id, { id: id },
                  function (res) {
                      if (res.Status > 0) {
                          alert("操作成功！");
                          xjgrid.Reload();
                      }
                      else {
                          alert("操作失败！");
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);